// 输入一个数字字符串, 通过单调栈的处理后, 返回最大值
// 当前元素入栈, 前提是(栈中该元素数字量不为2)
// 当大数据入栈, 栈顶元素如果在栈中, 以及后续之和大于等于2, 则被替换掉
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let initStr;
rl.on("line", (line)=>{
    if(initStr === undefined) {
        initStr =  line.trim()
        console.log(getResult(initStr))
        // clear
        initStr = undefined
    }

})

function getResult(initStr) {
    let stackObj = {}
    let reserveObj = {}
    let stack = []

    for (const char of initStr) {
        if(!stackObj[char]) {
            stackObj[char] = 0
        }
        if(!reserveObj[char]) {
            reserveObj[char] = 1
        } else {
            reserveObj[char]++
        }
    }

    // 开始
    let index = 0
    while(index < initStr.length) {
        let char = initStr[index]

        while(stack.length) {
            let top = stack.at(-1)
            if(Number(char) >= Number(top) && stackObj[top] + reserveObj[top] > 2) {
                stack.pop()
                stackObj[top]--
            }else {
                break
            }
        }

        if(stackObj[char] >= 2) {
            reserveObj[char]--
            index++
            break
        }

        stack.push(char)
        stackObj[char]++
        reserveObj[char]--
        index++
    }
    return stack.join("")
}